import java.util.ArrayList;

import info.gridworld.actor.Critter;
import info.gridworld.grid.Location;


public class KnightCritter extends Critter {
	Location currentLocation;
	ArrayList<Location> visitedLocations;
	
	public KnightCritter(){
		super();
		currentLocation = null;
		visitedLocations = new ArrayList<Location>();
	}
	
	public boolean alreadyVisited(Location l){
		for (Location a : visitedLocations){
			if (a.equals(l)){
				return true;
			}
		}
		return false;
	}
	
	

	
	public ArrayList<Location> getMoveLocations(){
		currentLocation = getLocation();
		ArrayList<Location> locs = new ArrayList<Location>();
		locs = null;
		
		if (getGrid().isValid(new Location(currentLocation.getRow() - 2, currentLocation.getCol() - 1))){
			moveTo(new Location(currentLocation.getRow() - 2, currentLocation.getCol() - 1));
			visitedLocations.add(currentLocation);
			locs.add(new Location(currentLocation.getRow() - 2, currentLocation.getCol() - 1));
		} 
		if (getGrid().isValid(new Location(currentLocation.getRow() - 2, currentLocation.getCol() + 1))){
			moveTo(new Location(currentLocation.getRow() - 2, currentLocation.getCol() + 1));
			visitedLocations.add(currentLocation);
			locs.add(new Location(currentLocation.getRow() - 2, currentLocation.getCol() + 1));
		}
		if (getGrid().isValid(new Location(currentLocation.getRow() - 1, currentLocation.getCol() - 2))){
			moveTo(new Location(currentLocation.getRow() - 1, currentLocation.getCol() - 2));
			visitedLocations.add(currentLocation);
			locs.add(new Location(currentLocation.getRow() - 1, currentLocation.getCol() - 2));
		}
		if (getGrid().isValid(new Location(currentLocation.getRow() - 1, currentLocation.getCol() + 2))){
			moveTo(new Location(currentLocation.getRow() - 1, currentLocation.getCol() + 2));
			visitedLocations.add(currentLocation);
			locs.add(new Location(currentLocation.getRow() - 1, currentLocation.getCol() + 2));
		}
		if (getGrid().isValid(new Location(currentLocation.getRow() + 1, currentLocation.getCol() - 2))){
			moveTo(new Location(currentLocation.getRow() + 1, currentLocation.getCol() - 2));
			visitedLocations.add(currentLocation);
			locs.add(new Location(currentLocation.getRow() + 1, currentLocation.getCol() - 2));
		}
		if (getGrid().isValid(new Location(currentLocation.getRow() + 1, currentLocation.getCol() + 2))){
			moveTo(new Location(currentLocation.getRow() + 1, currentLocation.getCol() + 2));
			visitedLocations.add(currentLocation);
			locs.add(new Location(currentLocation.getRow() + 1, currentLocation.getCol() + 2));
		}
		if (getGrid().isValid(new Location(currentLocation.getRow() + 2, currentLocation.getCol() - 1))){
			moveTo(new Location(currentLocation.getRow() + 2, currentLocation.getCol() - 1));
			visitedLocations.add(currentLocation);
			locs.add(new Location(currentLocation.getRow() + 2, currentLocation.getCol() - 1));
		}
		if (getGrid().isValid(new Location(currentLocation.getRow() + 2, currentLocation.getCol() + 1))){
			moveTo(new Location(currentLocation.getRow() + 2, currentLocation.getCol() + 1));
			visitedLocations.add(currentLocation);
			locs.add(new Location(currentLocation.getRow() + 2, currentLocation.getCol() + 1));
		} 
		return locs;
	}
	

}
